#include <cstdio>
#include <algorithm>
using namespace std;

const int maxn = 1010;
struct Cost {
  int cmd, job;
  bool operator < (const Cost &o) const { return job > o.job; }
} cost[maxn];

int main() {
  int k = 0, n, i, c, j;
  
  while (scanf("%d", &n) == 1 && n) {    
    for (i = 0; i < n; i++) {
      scanf("%d %d", &c, &j);
      cost[i].cmd = c;
      cost[i].job = j;
    }
    
    sort(cost, cost + n);
    
    int s = 0, total = 0;
    for (i = 0; i < n; i++) {
      s += cost[i].cmd;
      total = max(total, s + cost[i].job);
    }
    
    printf("Case %d: %d\n", ++k, total);
  }
  
  return 0;
}
